package com.jzg.jcptadmin.ui;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.LinearLayoutManager;
import android.widget.TextView;

import com.jzg.jcptadmin.R;
import com.jzg.jcptadmin.adpter.ExtendedViewPagerAdapter;
import com.jzg.jcptadmin.base.BaseActivity;
import com.jzg.jcptadmin.data.local.ACache;
import com.jzg.jcptadmin.data.vo.ImageList;
import com.jzg.jcptadmin.view.ExtendedViewPager;

import butterknife.Bind;
import butterknife.ButterKnife;
/**
*
* -本地图片查看
 * PhotoActivity
* @author sunbl
* created at 2016/1/21 16:09
*/
public class PhotoActivity extends BaseActivity {

    @Bind(R.id.extendedVP)
    ExtendedViewPager extendedVP;
    int position;
    @Bind(R.id.title)
    TextView title;
    private LinearLayoutManager linearLayoutManager;
    private ImageList list;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_photo);
        ButterKnife.bind(this);

        position = getIntent().getIntExtra("position", 0);
        Long id  =getIntent().getLongExtra("id",0);
        list = (ImageList) ACache.get(this).getAsObject(id+"");
        extendedVP.setAdapter(new ExtendedViewPagerAdapter(appContext, list.getLists()));
        extendedVP.setCurrentItem(position);
        linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        extendedVP.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                setShoePerNum(position);

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

//

        setShoePerNum(position);
    }
    private void setShoePerNum(int num) {
        num++;
        if (num <= 0)
            num = 1;
        if (list.getLists() != null)
            title.setText(num + "/" + list.getLists().size());
    }
}
